define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Distribution, $window, $timeout, $ionicSlideBoxDelegate, $ionicSideMenuDelegate,GoPage) {
		
		Distribution.get_distribution(function(data){
			$scope.distribution = data;
			
		});

		$scope.isLoad = false; //可以加载
		//画面加载
		$scope.$on('$ionicView.afterEnter', function() {
			//动态设置高度
			var all = $window.innerHeight;
			//计算滚动条
			$scope.myObj = {
				"height": all - 44 + "px"
			};
		}, false);
		//滑动时候触发
		$scope.selectIndex = 0;
		$scope.slideChanged = function(index) {
			//手指滑动
			$scope.selectIndex = index;
		};
		$scope.activeSlide = function(index) {
			$scope.selectIndex = index;
			$ionicSlideBoxDelegate.$getByHandle('main-handle').slide(index);
			//判断关闭
			if($ionicSideMenuDelegate.isOpenRight()) {
				$ionicSideMenuDelegate.toggleRight();
			}
		};
		//下拉刷新 判断哪个模块进行刷新
		$scope.doRefresh = function() {
			$timeout(function() {
				$scope.$broadcast('scroll.refreshComplete');
			}, 1000);
		};
		//加载更多
		$scope.doRefreshMore = function() {
			$timeout(function() {
				$scope.$broadcast('scroll.infiniteScrollComplete');
			}, 1000);
		};
		//侧边菜单
		$scope.rightSideMenu = function() {
			$ionicSideMenuDelegate.toggleRight();
		};
		//查询
		$scope.doSearch = function() {
			$ionicSideMenuDelegate.toggleRight();
		};
		//取消
		$scope.doCancel = function() {
			$ionicSideMenuDelegate.toggleRight();
		};
		
		$scope.onshow_post = function(){
			GoPage.go_states("newproductpost");
		}

		$scope.onshow_statistics = function(){
			GoPage.go_states("statistics");
		}
		$scope.onshow_start = function(){
			GoPage.go_states("statistics");
		}
        
        
	}

	controller.$inject = ['$scope', 'Distribution', '$window', '$timeout', '$ionicSlideBoxDelegate', '$ionicSideMenuDelegate','GoPage'];
	
	return app.registerController("distributionctrl",controller);
});